package utils

import (
	"sort"
)

type StringIntPair struct {
	First  string
	Second int
}

func KeysMapStringInt(m map[string]int) []string {
	keys := make([]string, 0, len(m))
	for k, _ := range m {
		keys = append(keys, k)
	}
	return keys
}

func SortMapStringIntByValue(m map[string]int) []StringIntPair {
	result := make([]StringIntPair, 0, len(m))
	for k, v := range m {
		result = append(result, StringIntPair{k, v})
	}
	sort.SliceStable(result, func(i, j int) bool {
		return result[i].Second < result[j].Second
	})
	return result
}